﻿@inherits ControlComponentBase
@if (Data != null)
{
    @if (Data.CtrType == WidgetType.SplitH)
    {
        <div style="z-index:@(Data.Zindex);height:@(Data.Height)%;position:relative" class="@(Data.IsSelect?"designer-select":"designer")" @onclick:stopPropagation="true">
            <Split Basis="@(Data.Basis.ToString()+"%")">
                <FirstPaneTemplate>
                    <div  class="cus-first-panel @(Data.Controls[0].IsSelect?"designer-select":"designer")" @onclick="async ()=>{await SetSelectedAsync(Data);}"
                         @onclick:stopPropagation="true">
                        @if (Data.Controls.Count > 0)
                        {
                            @foreach (var item in Data.Controls[0].Controls)
                            {
                                <ControlComponent Data="item" ParentData="Data.Controls[0]"></ControlComponent>
                            }
                        }
                        <DropArea Data="@Data.Controls[0]" ParentData="Data.Controls[0]"></DropArea>
                    </div>
                </FirstPaneTemplate>
                <SecondPaneTemplate>
                    <div  class="cus-first-panel @(Data.Controls[1].IsSelect?"designer-select":"designer")" @onclick="async ()=>{await SetSelectedAsync(Data);}"
                         @onclick:stopPropagation="true">
                        @if (Data.Controls.Count > 1)
                        {
                            @foreach (var item in Data.Controls[1].Controls)
                            {
                                <ControlComponent Data="item" ParentData="Data.Controls[1]"></ControlComponent>
                            }
                        }
                        <DropArea Data="@Data.Controls[1]" ParentData="Data.Controls[1]"></DropArea>
                    </div>
                </SecondPaneTemplate>
            </Split>
        </div>
    }
    else if (Data.CtrType == WidgetType.SplitV)
    {
        <div style="z-index:@(Data.Zindex);height:@(Data.Height)%;position:relative" class="@(Data.IsSelect?"designer-select":"designer")" @onclick:stopPropagation="true">
            <Split Basis="@(Data.Basis.ToString()+"%")" IsVertical="true">
                <FirstPaneTemplate>
                    <div  class="cus-first-panel @(Data.Controls[0].IsSelect?"designer-select":"designer")"
                         @onclick="async ()=>{await SetSelectedAsync(Data);}"
                         @onclick:stopPropagation="true">
                        @if (Data.Controls.Count > 0)
                        {
                            @foreach (var item in Data.Controls[0].Controls)
                            {
                                <ControlComponent Data="item" ParentData="Data.Controls[0]"></ControlComponent>
                            }
                            <DropArea Data="@Data.Controls[0]" ParentData="Data.Controls[0]"></DropArea>
                        }
                    </div>
                </FirstPaneTemplate>
                <SecondPaneTemplate>
                    <div  class="cus-first-panel @(Data.Controls[1].IsSelect?"designer-select":"designer")" @onclick="async ()=>{await SetSelectedAsync(Data);}"
                         @onclick:stopPropagation="true">
                        @if (Data.Controls.Count > 1)
                        {
                            @foreach (var item in Data.Controls[1].Controls)
                            {
                                <ControlComponent Data="item" ParentData="Data.Controls[1]"></ControlComponent>
                            }
                            <DropArea Data="@Data.Controls[1]" ParentData="Data.Controls[1]"></DropArea>
                        }
                    </div>
                </SecondPaneTemplate>
            </Split>
        </div>
    }
    else if (Data.CtrType == WidgetType.Row)
    {
        <div style="z-index:@(Data.Zindex);min-height:@(Data.MinHeight+Data.MinHeightUnit);" class="row cus-row @(Data.IsSelect?"designer-select":"")"
             @onclick="SelectComponentAsync"
             @onclick:stopPropagation="true">
            @foreach (var item in Data.Controls)
            {
                <div class="col-@(item.Width) offset-@(item.Offset)">
                    <ControlComponent Data="item" ParentData="@Data"></ControlComponent>
                </div>
            }
            <DropArea Data="@Data" ParentData="@Data"></DropArea>
        </div>
    }
    else if (Data.CtrType == WidgetType.InputText)
    {
        @if (Data.InputText != null)
        {
            <div style="z-index:@(Data.Zindex);display:@(Data.InputText.LabelPositon);" class="@(Data.IsSelect?"designer-select":"") cus-inputtext"
                 @onclick="SelectComponentAsync"
                 @onclick:stopPropagation="true">
                <BootstrapInput @bind-Value="Data.Values.ValueString"
                                PlaceHolder="@Data.InputText.PlaceHolder"
                                OnEnterAsync="OnEnterAsyncInputText"
                                OnEscAsync="OnEscAsyncInputText"
                                IsTrim="@Data.InputText.IsTrim"
                                IsDisabled="@Data.InputText.IsDisabled"
                                DisplayText="@Data.DisplayName"
                                IsAutoFocus="@Data.InputText.IsAutoFocus"
                                ShowLabel="@Data.InputText.ShowLabel"
                                Color="Data.InputText.Color">
                </BootstrapInput>
                <DropArea Data="@Data" ParentData="@ParentData"></DropArea>
            </div>
        }
    }
    else if (Data.CtrType == WidgetType.Table)
    {
        <div style="z-index:@(Data.Zindex);height:@(Data.Height)%" class="cus-table @(Data.IsSelect?"designer-select":"")"
             @onclick="SelectComponentAsync"
             @onclick:stopPropagation="true">
            <div class="cus-table-table">
                <Table TItem="DynamicObject" DynamicContext="DataTablePageDynamicContext"
                       IsFixedHeader="true"
                       TableSize="TableSize.Compact"
                       ShowColumnList="Data.TableInfo.ShowColumnList"
                       ShowLineNo="Data.TableInfo.ShowLineNo"
                       OnSort="OnSortTable"
                       ClickToSelect="true" 
                       OnClickRowCallback="OnClickedRow"
                       ShowToolbar="true" ShowDeleteButton="false" ShowSearchButton="false" ShowRefresh="false" ShowAddButton="false" ShowEditButton="false">
                    <TableToolbarTemplate>
                        <BootstrapInput @bind-Value="@SearchText" TValue="string"></BootstrapInput>
                        <Button Color="Color.Info" Icon="fas fa-search" Text="" OnClick="InitDataTable" />
                        <Button Color="Color.Info" Icon="fas fa-sync" Text="" OnClick="InitDataTable" />
                    </TableToolbarTemplate>
                </Table>
            </div>
            <div class="cus-table-pagination">
                <Pagination ShowGotoNavigator="false" ShowPageInfo="true" PageCount="@Data.TableInfo!.PageCount" PageIndex="@Data.TableInfo!.PageIndex" OnPageLinkClick="@OnPageLinkClick">
                    <PageInfoTemplate>
                        @if (Data != null && Data.TableInfo != null)
                        {
                            //overflow-y:hidden
                            <div class="page-info me-2">@($"一共:{Data.TableInfo.TotalCount}条")</div>
                            <Select @bind-Value="@Data.TableInfo.PageItems" Items="@Data.TableInfo.PageItemsSource" OnValueChanged="(e)=>{InitPageDataTable();return Task.CompletedTask;}" />
                        }
                    </PageInfoTemplate>
                </Pagination>
            </div>
            @* <DropArea Data="@Data" ParentData="ParentData"></DropArea> *@
        </div>
    }
    else if (Data.CtrType == WidgetType.Bottom)
    {
        @if (Data.Button != null)
        {
            <div style="z-index:@(Data.Zindex);" class="@(Data.IsSelect?"designer-select":"") cus-bottom"
                 @onclick="SelectComponentAsync"
                 @onclick:stopPropagation="true">
                <Button OnClick="ButtonClick"
                        Text="@Data.DisplayName"
                        Size="Data.Button.Size"
                        Color="Data.Button.Color"
                        Icon="@Data.Button.Icon"
                        IsDisabled="Data.Button.IsDisabled"
                        IsOutline="Data.Button.IsOutline"
                        IsAsync="Data.Button.IsAsync"
                        ButtonStyle="Data.Button.ButtonStyle">
                </Button>
                <DropArea Data="@Data" ParentData="ParentData"></DropArea>
            </div>
        }
    }
    else if (Data.CtrType == WidgetType.Tab)
    {
        <div style="z-index:@(Data.Zindex);position:relative;height:@(Data.Height)%" class="@(Data.IsSelect?"designer-select":"designer") cus-tab"
             @onclick:stopPropagation="true">
            <Tab OnClickTabItemAsync="OnClickTabItemAsync">
                @foreach (var item in Data.Controls)
                {
                    <TabItem Text="@item.DisplayName">
                        <div style="height:100%" @onclick="async()=>{await SetSelectedAsync(item);}" class="@(item.IsSelect?"designer-select":"") cus-tab-tabitem"
                             @onclick:stopPropagation="true">
                            @foreach (var item2 in item.Controls)
                            {
                                <ControlComponent Data="item2" ParentData="@item"></ControlComponent>
                            }
                            <DropArea Data="@item" ParentData="@item"></DropArea>
                        </div>
                    </TabItem>
                }

                @*   <TabItem Text="菜单管理">
        <div class="yonghuguanli" style="position:relative;height:100%">
        <div>菜单管理</div>
        <DropArea Data="@Data" ParentData="ParentData"></DropArea>
        </div>
        </TabItem> *@
            </Tab>


        </div>
    }
    else if (Data.CtrType == WidgetType.None)
    {
        <div style="position:relative;height:100%;width:100%" class="@(Data.IsSelect?"designer-select":"designer")" @onclick="SelectComponentAsync"
             @onclick:stopPropagation="true">
            @foreach (var item in Data.Controls)
            {
                <ControlComponent Data="item" ParentData="Data"></ControlComponent>
            }
            <DropArea Data="@Data" ParentData="ParentData"></DropArea>

        </div>

    }
    else if (Data.CtrType == WidgetType.CheckBox)
    {
        @if (Data.CheckBox != null)
        {
            <div style="z-index:@(Data.Zindex);" class="@(Data.IsSelect?"designer-select":"") cus-check"
                 @onclick="SelectComponentAsync"
                 @onclick:stopPropagation="true">
                <Checkbox @bind-Value=@Data.Values.ValueBool
                          IsDisabled="@Data.CheckBox.IsDisabled"
                          Size="@Data.CheckBox.Size"
                          Color="@Data.CheckBox.Color"
                          DisplayText="@Data.DisplayName"
                          ShowAfterLabel="@Data.CheckBox.ShowLabel"
                          ShowLabel="false">
                </Checkbox>
                <DropArea Data="@Data" ParentData="@ParentData"></DropArea>
            </div>
        }
    }
}




